﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;

namespace Common.Behaviors
{
    public class ProjectionAnimation : TargetedTriggerAction<FrameworkElement>
    {
        // properties
        public TimeSpan Time { get; set; } // how long must the animation take
        public double Rotation {get; set;} // Angle of the rotation
        public enum Axis { X,Y,Z };
        public Axis RotationAxis { get; set; } // Axis of the rotation

        // invoke method wil execute the behaviour
        protected override void Invoke(object parameter)
        {
            // get the element that must be animated
            FrameworkElement myElement = this.AssociatedObject as FrameworkElement;

            // create a new Projection
            myElement.RenderTransformOrigin = new Point(0.5, 0.5);
            PlaneProjection pj = new PlaneProjection();
            myElement.Projection = pj;

            // start the animation depending on the choosen axis
            switch (RotationAxis)
            {
                case Axis.X:
                    Animation.playAnimation(myElement.Name, "(UIElement.Projection).(PlaneProjection.RotationX)", this.Time, this.Rotation);
                    break;
                case Axis.Y:
                    Animation.playAnimation(myElement.Name, "(UIElement.Projection).(PlaneProjection.RotationY)", this.Time, this.Rotation);
                    break;
                case Axis.Z:
                    Animation.playAnimation(myElement.Name, "(UIElement.Projection).(PlaneProjection.RotationZ)", this.Time, this.Rotation);
                    break;
            }
       }
    }
}
